<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript" src="js/angular.js" ></script>
	</head>
	<body>
		<div ng-app="myApp" ng-controller="myCtrl">
			 {{r}}
		</div>
		<script type="text/javascript">
			var app=angular.module('myApp',[]);
			app.factory('myFactory',function(){
				var service={};//定义一个object对象
				var age;
				service.name="张三";
			
				service.setAge=function(newAge){
					age=newAge;
				}
				service.getAge=function(){
					return age;
				}
			return service;
		})
			app.controller('myCtrl',function($scope,myFactory){
			myFactory.setAge(20);
			$scope.r=myFactory.getAge();
			alert(myFactory.name);
				
				
			})
		</script>
	</body>
</html>
